﻿using System;
using System.Web;
using System.Web.Caching;
using System.Data;

namespace Com.Framework.Cache
{
	public class CacheUtil
	{
		public CacheUtil()
		{
		}

		public static void Insert(string strCacheName, object objValue, int n4CachingMinute)
		{
			Random rnd = new Random();
			int n4RandomValue = (rnd.Next() % 20) - 10;
			DateTime dateExpire = DateTime.Now.AddSeconds((n4CachingMinute * 60) + n4RandomValue);

			HttpContext.Current.Cache.Insert(strCacheName, objValue, null, dateExpire, System.Web.Caching.Cache.NoSlidingExpiration);
		}

		public static void Insert(string strCacheName, object objValue, DateTime dateExpire)
		{
			HttpContext.Current.Cache.Insert(strCacheName, objValue, null, dateExpire, System.Web.Caching.Cache.NoSlidingExpiration);
		}

		public static object Get(string strCacheName)
		{
			return HttpContext.Current.Cache.Get(strCacheName);
		}

		public static object Remove(string strCacheName)
		{
			return HttpContext.Current.Cache.Remove(strCacheName);
		}
	}
}
